import os

from utils import read_config as config, k_util, functions_ths, date_util, excel_util, doc_util, chart_util, caiptal_util
from service import data_service
from database.mapper import stock_day_k


# 验证大资金
def main_io_yz(code):
    print('验证大资金')
    main_100 = caiptal_util.flow_hundred(code)[0:100]
    sp_100 = stock_day_k.select_size(code, 100)
    main_sort = sorted(main_100, key=lambda x: x['main_io'])
    sp_sort = sorted(sp_100, key=lambda x: x['sp'])
    max_sp = sp_sort[len(sp_sort) - 1].get('sp')
    min_sp = sp_sort[0].get('sp')
    max_main = float(main_sort[len(main_sort) - 1].get('main_io'))
    min_main = main_sort[0].get('main_io')
    bs = round((max_main - min_main) / (max_sp - min_sp))
    # bs = round(max_main / max_sp, 2)
    main_100.reverse()
    sp_100.reverse()

    y = []
    x = []
    x0 = []
    x1 = []
    x2 = []
    y0 = []
    y1 = []
    y2 = []
    five_total = 0
    for i in range(100):
        five_total += float(main_100[i].get('main_io'))
        y0.append(min_sp)
        x0.append(i + 1)
        if (i + 1) % 4 == 0:
            x1.append(i + 1)
            y1.append(round(five_total / bs + min_sp, 2))
            five_total = 0
        if (i + 1) % 1 == 0:
            y2.append(sp_100[i].get('sp'))
            x2.append(i + 1)
    x.append(x0)
    x.append(x1)
    x.append(x2)
    y.append(y0)
    y.append(y1)
    y.append(y2)
    chart_util.line_chart(x, y, code, 'rq', 'jg', 1)


if __name__ == '__main__':
    # sniper()
    # main_io_yz('600588')
    # main_io_yz('601633')
    # main_io_yz('000063')
    main_io_yz('002594')
